usage(){
  echo "Usage: deploy.sh service [command]"
  echo "    service = light4j | logserver | info | apidemo"
  echo "    command = start | stop | status | restart | rebuild | redeploy"
  exit 0
}
command="$2"
light4j(){
    cd /soft/gitdata/light4j
    git pull
    sh start.sh $command
}
logserver(){
    cd /soft/gitdata/logserver
    git pull
    sh start.sh $command
}
apidemo(){
	update="$command"
	if [ ! -f ${update} ]; then
	    echo "no update.tgz"
	else
	    mv update.tgz /soft/wwwroot
	    cd /soft/wwwroot
	    if [ -d apidemo ]; then
	    rm -rf apidemo.`date +%Y%m%d%H%M`
	    mv apidemo apidemo.`date +%Y%m%d%H%M`
	    sleep 1
	    fi
	    tar zxvf update.tgz
	    mv web apidemo
	    rm -f update.tgz
	fi
}
info(){
	update="$command"
	if [ ! -f ${update} ]; then
	    echo "update light-info"
	    cd /soft/gitdata/info
	    git pull
	    sh start.sh $command
	else
	    echo "update uni-info"
	    mv update.tgz /soft/gitdata/info
	    cd /soft/gitdata/info
	    if [ -d public ]; then
	    rm -rf public.`date +%Y%m%d%H%M`
	    mv public public.`date +%Y%m%d%H%M`
	    sleep 1
	    fi
	    tar zxvf update.tgz
	    mv web public
	    rm -f update.tgz
	fi
}
if [ $# -eq 0 ]; then 
    usage
else
	case $1 in
	light4j) light4j ;;
	logserver) logserver ;;
	info) info ;;
	apidemo) apidemo;;
	*) usage ;;
	esac
fi
